package com.gzhryc.net_marketing.cloud.business.dao;

import java.sql.SQLException;
import java.util.List;

import com.gzhryc.jdbc.BaseDao;
import com.gzhryc.jdbc.Conditions;
import com.gzhryc.jdbc.Query;
import com.gzhryc.net_marketing.cloud.business.dao.db.TeamPayApplyMember;
import com.gzhryc.net_marketing.cloud.business.dao.models.TeamPayApplyMemberStateCount;

public class TeamPayApplyMemberDao extends BaseDao<TeamPayApplyMember> {

	public TeamPayApplyMemberDao(String jdbcKey) {
		super(jdbcKey);
	}

	public Integer getMaxPriority(Long applyId) throws SQLException {
		String sql = "SELECT MAX(priority) FROM " + this.tableName + " WHERE apply_id = ?";
		Query query = new Query(sql);
		query.getParams().setObject(applyId);
		return this.jdbcHelper.getFirstField(query, Integer.class);
	}

	public List<TeamPayApplyMemberStateCount> countByGroupState(Conditions conditions) throws SQLException {
		String sql = "SELECT state,count(1) AS total FROM " + this.tableName;
		Query query = new Query(sql);
		query.appendSql(conditions.toSql(query.getParams(),true));
		query.appendSql(" GROUP BY state");
		return this.jdbcHelper.find(query, TeamPayApplyMemberStateCount.class);
	}
}
